import java.util.Stack;

/*
 * @lc app=leetcode.cn id=150 lang=java
 *
 * [150] 逆波兰表达式求值
 */

// @lc code=start
class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> st = new Stack<>();
        for(String i : tokens){
            if(i.length()>1 || Character.isDigit(i.charAt(0))){
                st.push(Integer.parseInt(i));
            }else{
                int num2 = st.pop();
                int num1 = st.pop();
                switch (i.charAt(0)) {
                    case '+':
                        st.push(num1+num2);
                        break;
                    case '-':
                        st.push(num1-num2);
                        break;
                    case '*':
                        st.push(num1*num2);
                        break;
                    case '/':
                        st.push(num1/num2);
                        break;
                    default:
                        break;
                }
                
            }
        }

        return st.pop();
    }
}


// @lc code=end

